/*
 * Copyright 2018- The Pixie Authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 */

syntax = "proto3";

package px.vizier.services.shared.agent;

option go_package = "agentpb";

import "github.com/gogo/protobuf/gogoproto/gogo.proto";
import "src/api/proto/uuidpb/uuid.proto";

// AgentCapabilities describes functions that the agent has available.
message AgentCapabilities {
  bool collects_data = 1;
}

message AgentParameters {
  int32 profiler_stack_trace_sample_period_ms = 1
      [ (gogoproto.customname) = "ProfilerStackTraceSamplePeriodMS" ];
}

// AgentInfo contains information about host and agent running on a given machine.
message AgentInfo {
  uuidpb.UUID agent_id = 1 [ (gogoproto.customname) = "AgentID" ];
  HostInfo host_info = 2;
  string ip_address = 3 [ (gogoproto.customname) = "IPAddress" ];
  AgentCapabilities capabilities = 4;
  AgentParameters parameters = 5;
}

message KernelVersion {
  uint32 version = 1;
  uint32 major_rev = 2;
  uint32 minor_rev = 3;
}

// HostInfo contains the details for the host (OS, kernel, CPU, etc).
message HostInfo {
  // The Hostname as reported by pod. This will be the machine hostname for Daemonsets and assigned
  // hostname for regular pods (kelvin).
  string hostname = 1;
  // The Hostname is not always unique. EKS autoscaling groups assign all nodes the same hostname so
  // we use this to disambiguate the different PEMs.
  string pod_name = 2;
  // The IP of the host that pod is running on. This can used to avoid extra K8s lookups.
  string host_ip = 3 [ (gogoproto.customname) = "HostIP" ];
  // Version of the kernel running on the host.
  KernelVersion kernel = 4;
}

// Agent contains information about a specific agent instance.
message Agent {
  AgentInfo info = 1;
  int64 create_time_ns = 2 [ (gogoproto.customname) = "CreateTimeNS" ];
  int64 last_heartbeat_ns = 3 [ (gogoproto.customname) = "LastHeartbeatNS" ];
  // The agent counter used by the metadata service.
  uint32 asid = 4 [ (gogoproto.customname) = "ASID" ];
}

enum AgentState {
  // The default state if nothing is known.
  AGENT_STATE_UNKNOWN = 0;
  // The state is healthy if heartbeats are received on regular intervals and the
  // agent is responding to requests.
  AGENT_STATE_HEALTHY = 1;
  // The state will go to unresponsive if the agent hasn't sent a heartbeat for a while
  // or is unresponsive to messages from Vizier.
  AGENT_STATE_UNRESPONSIVE = 2;
  // The state will go to disconnected if the GRPC connection breaks. The hope is that the agent
  // will come back online and resume in HEALTHY state.
  AGENT_STATE_DISCONNECTED = 3;
}

// AgentStatus contains information about the status of an agent.
message AgentStatus {
  int64 ns_since_last_heartbeat = 1 [ (gogoproto.customname) = "NSSinceLastHeartbeat" ];
  // The state of the Agent.
  AgentState state = 2;
}
